﻿<%@ Page Language="vb" AutoEventWireup="false" MasterPageFile="~/WebForm/MasterPage.master"
    CodeFile="ManageCodeMapping.aspx.vb" Inherits="WebForm_ManageCodeMapping" %>
<%@ Register Namespace="My" TagPrefix="cc1" %>
<%@ Register Assembly="App_Code" Namespace="My" TagPrefix="My" %>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<script type="text/javascript">
  function   JHshNumberText()   
  {   
      if(!(((window.event.keyCode>=48)&&(window.event.keyCode<=57))||(window.event.keyCode==13)||(window.event.keyCode==46)||(window.event.keyCode==45)))   
      {   
            window.event.keyCode=0;   
      }   
  }   
</script> 
    <table width="95%" align="Center">
        <tr>
            <td align="center">
                <asp:Label ID="Title" runat="server" SkinID="title" meta:resourcekey="Title"></asp:Label>
            </td>
        </tr>
        <tr>
            <td>
            
            <asp:UpdatePanel ID="UpdatePanel3" runat="server" UpdateMode="Conditional">
            <ContentTemplate>
                <TABLE id="table1" cellSpacing=0 cellPadding=0 width="100%" border=0><TBODY><TR><TD align=center><TABLE cellSpacing=0 cellPadding=0 width="99%" border=0><TBODY>
            <TR><TD align=left><asp:Panel id="pnlADD" runat="server"><asp:FormView id="fv" runat="server" DataSourceID="fv_DS" DefaultMode="Insert" DataKeyNames="EmployeeID"><InsertItemTemplate>
            <TABLE style="WIDTH: 600px"><TBODY><TR><TD style="WIDTH: 20%" align=right><asp:Label id="lblTableName" runat="server" meta:resourcekey="lblTableName" __designer:wfdid="w139"></asp:Label></TD><TD style="WIDTH: 15%"><asp:DropDownList id="ddlTableName" runat="server" __designer:wfdid="w140" DataSourceID="SqlDataSource1" OnSelectedIndexChanged="ddlTableName_SelectedIndexChanged" OnDataBound="ddlTableName_DataBound" AutoPostBack="True" DataTextField="Text" DataValueField="TableName">
                                    </asp:DropDownList><asp:SqlDataSource id="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:connStr %>" SelectCommand="Select * from CodeList where TableName=ColumnName and Active='Y'" __designer:wfdid="w141"></asp:SqlDataSource> </TD><TD style="WIDTH: 20%" align=right><asp:Label id="lblColumnName" runat="server" meta:resourcekey="lblColumnName" __designer:wfdid="w142"></asp:Label></TD><TD style="WIDTH: 15%"><asp:DropDownList id="ddlColumnName" runat="server" __designer:wfdid="w143" DataSourceID="SqlDataSource2" OnSelectedIndexChanged="ddlColumnName_SelectedIndexChanged" OnDataBound="ddlColumnName_DataBound" AutoPostBack="True" DataTextField="Text" DataValueField="ColumnName">
                                    </asp:DropDownList><asp:SqlDataSource id="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:connStr %>" SelectCommand="select b.* from CodeList a left join CodeList b&#13;&#10;on a.TableName=b.TableName and b.TableName<>b.ColumnName&#13;&#10; where a.TableName=a.ColumnName and a.TableName=@TableName and a.Active='Y' and b.Active='Y'" __designer:wfdid="w144">
                                        <SelectParameters>
                                            <asp:ControlParameter ControlID="ddlTableName" Name="TableName" PropertyName="SelectedValue" />
                                        </SelectParameters>
                                    </asp:SqlDataSource> </TD><TD align=left colSpan=2><asp:Label id="lblSequence" runat="server" meta:resourcekey="lblSequence" __designer:wfdid="w145"></asp:Label> <asp:TextBox id="txtSequence" onkeypress="JHshNumberText()" runat="server" Text='<%# Bind("Sequence") %>' __designer:wfdid="w146" MaxLength="3" Width="36px"></asp:TextBox></TD></TR><TR><TD style="WIDTH: 20%" align=right><asp:Label id="lblText" runat="server" meta:resourcekey="lblText" __designer:wfdid="w147"></asp:Label></TD><TD style="WIDTH: 15%"><asp:TextBox id="txtText" runat="server" Text='<%# Bind("Text") %>' MaxLength="50" __designer:wfdid="w148"></asp:TextBox></TD><TD style="WIDTH: 20%" align=right><asp:Label id="lblValue" runat="server" meta:resourcekey="lblValue" __designer:wfdid="w149"></asp:Label></TD><TD style="WIDTH: 15%"><asp:TextBox id="txtValue" runat="server" Text='<%# Bind("Value") %>' MaxLength="50" __designer:wfdid="w150"></asp:TextBox></TD><TD align=left colSpan=2>
                                    <asp:Button ID="btnAdd" ValidationGroup="vInsert" CommandName="Insert" runat="server" meta:resourcekey="btnAdd" />
                                    <asp:RequiredFieldValidator id="rfvTableName" runat="server" meta:resourcekey="rfvTableName" ValidationGroup="vInsert" __designer:wfdid="w152" ControlToValidate="ddlTableName" Display="None" SetFocusOnError="True" InitialValue="0">*</asp:RequiredFieldValidator><asp:RequiredFieldValidator id="rfvColumnName" runat="server" meta:resourcekey="rfvColumnName" ValidationGroup="vInsert" __designer:wfdid="w153" ControlToValidate="ddlColumnName" Display="None" SetFocusOnError="True" InitialValue="0">*</asp:RequiredFieldValidator><asp:RequiredFieldValidator id="rfvText" runat="server" meta:resourcekey="rfvText" ValidationGroup="vInsert" __designer:wfdid="w154" ControlToValidate="txtText" Display="None" SetFocusOnError="True">*</asp:RequiredFieldValidator><asp:RequiredFieldValidator id="rfvValue" runat="server" meta:resourcekey="rfvValue" ValidationGroup="vInsert" __designer:wfdid="w155" ControlToValidate="txtValue" Display="None" SetFocusOnError="True">*</asp:RequiredFieldValidator><asp:ValidationSummary id="ValidationSummary1" runat="server" ShowMessageBox="True" ShowSummary="False" ValidationGroup="vInsert" __designer:wfdid="w156"></asp:ValidationSummary> </TD></TR></TBODY></TABLE>
            </InsertItemTemplate>
            </asp:FormView> </asp:Panel> <asp:SqlDataSource id="fv_DS" runat="server" ConnectionString="<%$ ConnectionStrings:connStr %>" InsertCommand="INSERT INTO [CodeMapping] ([TableName], [ColumnName], [Value], [Text], [Configurable], [Sequence]) VALUES (@TableName, @ColumnName, @Value, @Text, 'Y', @Sequence)">
                <InsertParameters>
                    <asp:Parameter Name="TableName" Type="String" />
                    <asp:Parameter Name="ColumnName" Type="String" />
                    <asp:Parameter Name="Value" Type="String" />
                    <asp:Parameter Name="Text" Type="String" />
                    <asp:Parameter Name="Configurable" Type="String" />
                    <asp:Parameter Name="Sequence" Type="Int32" />
                </InsertParameters>
            </asp:SqlDataSource> <BR /><asp:Panel id="pnlList" runat="server">
            <My:MyGridView id="gv" runat="server" meta:resourcekey="gv" SkinID="pager" DataSourceID="gv_DS" DataKeyNames="ID" AllowPaging="True" AllowSorting="True">
            <PagerSettings Position="Top"></PagerSettings>
            <Columns>
            <asp:TemplateField HeaderText="NO" InsertVisible="False">
                                                    <ItemTemplate>
                                                        <%#gv.PageIndex * gv.PageSize + gv.Rows.Count + 1%>
                                                    </ItemTemplate>

            <ItemStyle HorizontalAlign="Center"></ItemStyle>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="TableName" SortExpression="TableName_Text" meta:resourceKey="gvTableName"><EditItemTemplate>
            <asp:DropDownList id="ddlTableName" runat="server" DataSourceID="SqlDataSource1" __designer:wfdid="w107" DataValueField="TableName" DataTextField="Text" AutoPostBack="True" OnSelectedIndexChanged="ddlTableName_SelectedIndexChanged1"></asp:DropDownList> <asp:HiddenField id="hideTableName" runat="server" __designer:wfdid="w108" Value='<%# Eval("TableName") %>'></asp:HiddenField> <asp:SqlDataSource id="SqlDataSource1" runat="server" SelectCommand="Select * from CodeList where TableName=ColumnName and Active='Y'" ConnectionString="<%$ ConnectionStrings:connStr %>" __designer:wfdid="w110"></asp:SqlDataSource> 
            </EditItemTemplate>
            <ItemTemplate>
            <asp:Label id="Label1" runat="server" Text='<%# Eval("TableName_Text") %>'></asp:Label> 
            </ItemTemplate>

            <ItemStyle HorizontalAlign="Center"></ItemStyle>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="ColumnName" SortExpression="ColumnName_Text" meta:resourceKey="gvColumnName"><EditItemTemplate>
            <asp:DropDownList id="ddlColumnName" runat="server" DataSourceID="SqlDataSource2" __designer:wfdid="w111" DataValueField="ColumnName" DataTextField="Text">
                        </asp:DropDownList> <asp:HiddenField id="hideColumnName" runat="server" __designer:wfdid="w112" Value='<%# Eval("ColumnName") %>'></asp:HiddenField> <asp:SqlDataSource id="SqlDataSource2" runat="server" SelectCommand="select b.* from CodeList a left join CodeList b&#13;&#10;on a.TableName=b.TableName and b.TableName<>b.ColumnName&#13;&#10; where a.TableName=a.ColumnName and a.TableName=@TableName" ConnectionString="<%$ ConnectionStrings:connStr %>" __designer:wfdid="w114">
                                <SelectParameters>
                                    <asp:ControlParameter ControlID="ddlTableName" Name="TableName" PropertyName="SelectedValue" />
                                </SelectParameters>
                            </asp:SqlDataSource> 
            </EditItemTemplate>
            <ItemTemplate>
            <asp:Label runat="server" Text='<%# Eval("ColumnName_Text") %>' id="Label2"></asp:Label>
            </ItemTemplate>

            <ItemStyle HorizontalAlign="Center"></ItemStyle>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Text" SortExpression="Text" meta:resourceKey="gvText"><EditItemTemplate>
            <asp:TextBox id="txtText" runat="server" Text='<%# Bind("Text") %>' __designer:wfdid="w138" MaxLength="50"></asp:TextBox><asp:RequiredFieldValidator id="rfvText" runat="server" meta:resourcekey="rfvText" ValidationGroup="vUpdate" __designer:wfdid="w157" ControlToValidate="txtText" Display="None" SetFocusOnError="True">*</asp:RequiredFieldValidator>
            </EditItemTemplate>
            <ItemTemplate>
                            <asp:Label ID="lblText" runat="server" Text='<%# Bind("Text") %>'></asp:Label>
                        
            </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Value" SortExpression="Value" meta:resourceKey="gvValue"><EditItemTemplate>
            <asp:TextBox id="txtValue" runat="server" Text='<%# Bind("Value") %>' __designer:wfdid="w158" MaxLength="50"></asp:TextBox><asp:RequiredFieldValidator id="rfvValue" runat="server" meta:resourcekey="rfvValue" ValidationGroup="vUpdate" __designer:wfdid="w159" ControlToValidate="txtValue" Display="None" SetFocusOnError="True">*</asp:RequiredFieldValidator>
            </EditItemTemplate>
            <ItemTemplate>
                            <asp:Label ID="Label4" runat="server" Text='<%# Bind("Value") %>'></asp:Label>
                        
            </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Sequence" SortExpression="Sequence" meta:resourceKey="gvSequence"><EditItemTemplate>
            <asp:TextBox id="txtSequence" runat="server" onkeypress="JHshNumberText()" Text='<%# Bind("Sequence") %>' __designer:wfdid="w117" Width="36px" MaxLength="3"></asp:TextBox>
            </EditItemTemplate>
            <ItemTemplate>
            <asp:Label runat="server" Text='<%# Bind("Sequence") %>' id="Label5"></asp:Label>
            </ItemTemplate>

            <ItemStyle HorizontalAlign="Center"></ItemStyle>
            </asp:TemplateField>
            <asp:TemplateField><EditItemTemplate>
            <asp:LinkButton id="linkbUpdate" runat="server" meta:resourcekey="linkbUpdate" ValidationGroup="vUpdate" __designer:wfdid="w160" CommandName="Update" ForeColor="Black"></asp:LinkButton>&nbsp;<asp:LinkButton id="linkbCancel" runat="server" meta:resourcekey="linkbCancel" __designer:wfdid="w161" CommandName="Cancel" ForeColor="Black"></asp:LinkButton> <asp:ValidationSummary id="ValidationSummary1" runat="server" ShowMessageBox="True" ShowSummary="False" ValidationGroup="vUpdate" __designer:wfdid="w162"></asp:ValidationSummary> 
            </EditItemTemplate>
            <ItemTemplate>
            <asp:LinkButton id="linkbEdit" runat="server" CommandName="Edit" meta:resourcekey="linkbEdit"></asp:LinkButton>&nbsp;
            <asp:LinkButton id="linkbDelete" runat="server" CommandName="Delete" meta:resourcekey="linkbDelete"></asp:LinkButton>
                    <ajaxToolkit:ConfirmButtonExtender TargetControlID="linkbDelete" ID="cbelinkbDelete" meta:resourcekey="cbelinkbDelete" runat="server">
                    </ajaxToolkit:ConfirmButtonExtender>
            </ItemTemplate>

            <ItemStyle HorizontalAlign="Center"></ItemStyle>
            </asp:TemplateField>
            </Columns>

            <FooterStyle BackColor="White" BorderWidth="0px"></FooterStyle>

            <HeaderStyle HorizontalAlign="Center"></HeaderStyle>
            </My:MyGridView> </asp:Panel> <asp:SqlDataSource id="gv_DS" runat="server" ConnectionString="<%$ ConnectionStrings:connStr %>" DeleteCommand="DELETE FROM [CodeMapping] WHERE [ID] = @ID" SelectCommand="SELECT a.*,b.Text as TableName_Text,c.Text as ColumnName_Text FROM [CodeMapping] a&#13;&#10;left join CodeList b on a.TableName=b.TableName and b.TableName=b.ColumnName&#13;&#10;left join CodeList c on a.TableName=c.TableName and a.ColumnName=c.ColumnName&#13;&#10;and c.TableName<>c.ColumnName WHERE ((a.TableName = @TableName or @TableName='0') AND (a.ColumnName = @ColumnName or @ColumnName='0')) and b.Active='Y' and c.Active='Y' ORDER BY a.TableName,a.ColumnName,Sequence" UpdateCommand="UPDATE [CodeMapping] SET [TableName] = @TableName, [ColumnName] = @ColumnName, [Value] = @Value, [Text] = @Text, [Sequence] = @Sequence WHERE [ID] = @ID">
                <DeleteParameters>
                    <asp:Parameter Name="ID" Type="Int32" />
                </DeleteParameters>
                <SelectParameters>
                    <asp:Parameter Name="TableName" Type="String" />
                    <asp:Parameter Name="ColumnName" Type="String" />
                </SelectParameters>
                <UpdateParameters>
                    <asp:Parameter Name="TableName" Type="String" />
                    <asp:Parameter Name="ColumnName" Type="String" />
                    <asp:Parameter Name="Value" Type="String" />
                    <asp:Parameter Name="Text" Type="String" />
                    <asp:Parameter Name="Sequence" Type="Int32" />
                    <asp:Parameter Name="ID" Type="Int32" />
                </UpdateParameters>
            </asp:SqlDataSource>&nbsp; </TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE>
            </ContentTemplate>
            </asp:UpdatePanel> 
            </td>
        </tr>
    </table>
</asp:Content>
